#ifndef UnorderedMap_h
#define UnorderedMap_h
#include "HashTable.hpp"
namespace yfy
{

template <class K, class V, class Hash = bucket_hash::HashFunc<K>>
class unordered_map
{
    struct MapKeyOfT
    {
        const K& operator()(const pair<const K, V>& kv) const
        {
            return kv.first;
        }
    };
public:
    typedef typename bucket_hash::HashTable<K, pair<const K, V>, Hash, MapKeyOfT>::iterator iterator;
    iterator begin()
    {
        return _ht.begin();
    }
    iterator end()
    {
        return _ht.end();
    }
    V& operator[](const K& key)
    {
        pair<iterator, bool> ret = _ht.insert(make_pair(key, V()));
        return ret.first->second;
    }
    pair<iterator, bool> insert(const pair<const K, V>& kv)
    {
        return _ht.insert(kv);
    }
private:
    bucket_hash::HashTable<K, pair<const K, V>, Hash, MapKeyOfT> _ht;
    
};

void test_unordered_map()
{
    unordered_map<string, string> dict;
    dict.insert(make_pair("string", "字符串"));
    dict.insert(make_pair("map", "地图"));
    dict.insert(make_pair("sort", "排序"));
    dict["end"] = "结束";
    dict["map"] += "，映射";
    auto it = dict.begin();
    while(it != dict.end())
    {
        cout << (*it).first << ":" << (*it).second << endl;
        ++it;
    }
}

}
#endif /* UnorderedMap_h */
